package top.lrshuai.websocket.ws.entity;

import lombok.Data;

import java.io.Serializable;

/**
 * ws 传输的格式，全部用这个DTO
 */
@Data
public class WebSocketDTO implements Serializable {
    /**
     * 模块名称
     *
     */
    private String moduleName;
    private Integer online;
    private Integer code;
    private String message;
    public static String SUCCESS="success";

    /**
     * 数据体
     */
    private Object data;


    private WebSocketDTO(Object data){
        this.data=data;
        this.code=0;
        this.message=SUCCESS;
//        this.online= ChannelGroupUtil.getInstance().getChannelGroup().size();
    }
    private WebSocketDTO(Integer code,Object data){
        this.code=code;
        this.data=data;
    }
    private WebSocketDTO(Integer code,String message,Object data){
        this.message=message;
        this.code=code;
        this.data=data;
    }

    /**
     * 心跳
     * @return
     */
    public static WebSocketDTO pong(){
        WebSocketDTO dto = new WebSocketDTO("PONG");
        dto.setModuleName(ModuleEnum.HEART_CHECK.getName());
        return dto;
    }

    /**
     * 传输数据
     * @param data
     * @return
     */
    public static WebSocketDTO data(Object data){
        WebSocketDTO dto = new WebSocketDTO(data);
        dto.setModuleName(ModuleEnum.DATA.getName());
        return dto;
    }

    public static WebSocketDTO data(Object data,ModuleEnum moduleEnum){
        WebSocketDTO dto = new WebSocketDTO(data);
        dto.setModuleName(moduleEnum.getName());
        return dto;
    }
    public static WebSocketDTO data(Object data,String module){
        WebSocketDTO dto = new WebSocketDTO(data);
        dto.setModuleName(module);
        return dto;
    }
}
